<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:s="http://jboss.com/products/seam/taglib">

  <ui:composition template="template.xhtml">
  
    <ui:define name="head">
      <link href="style/security.css" rel="stylesheet" type="text/css"/>
    </ui:define>  
   
    <ui:define name="content">
        
      <script type="text/javascript">
        function confirmDelete()
        {
          return confirm("Are you sure you wish to delete this user? This action cannot be undone.");
        }
      </script>

      <div id="contentMain">

  	    <h2>User Manager</h2>  
  	    
        <s:button id="newUser" action="#{userAction.createUser}" styleClass="newuser" rendered="#{s:hasPermission('seam.account', 'create')}"/>
  	    
        <h:dataTable 
            id="threads"
            value="#{users}" 
            var="user" 
            styleClass="security"
            cellspacing="0"
            headerClass="header"
            rowClasses="odd,even"
            columnClasses=",,enabled,action">
          <h:column width="auto">
            <f:facet name="header">
              User name
            </f:facet>
            #{user}
          </h:column>
          <h:column width="auto">
            <f:facet name="header">
              Member Of
            </f:facet>
            #{userSearch.getUserRoles(user)}
          </h:column>
          <h:column id="enabled" width="auto">
            <f:facet name="header">
              Enabled
            </f:facet>
            <div class="#{identityManager.isUserEnabled(user) ? 'checkmark' : 'cross'}"/>
          </h:column>
          <h:column id="action" width="auto">
            <f:facet name="header">
              Action
            </f:facet>
          
            <s:fragment rendered="#{s:hasPermission('seam.user', 'update')}">
              <s:link id="edit" value="Edit" action="#{userAction.editUser(userSearch.selectedUser)}"/><span> | </span>
            </s:fragment>
            <s:link id="delete" value="Delete" action="#{identityManager.deleteUser(userSearch.selectedUser)}" 
                    rendered="#{s:hasPermission('seam.user', 'delete')}"
                    onclick="return confirmDelete()"/>
          </h:column>
  	    </h:dataTable>
	    </div>
	    
    </ui:define>
    
  </ui:composition>
</html>
